#ifndef _P2P_PIECE_H_
#define _P2P_PIECE_H_

#include "p2p-config.h"

typedef struct piece_t {
    uint32_t index;
    uint32_t block[NO_OF_BLOCKS];
    struct piece_t *prev;
    struct piece_t *next;
} piece_t;

piece_t *init_piece(uint32_t index);
int reset_piece(piece_t *piece);
piece_t *add_piece(piece_t *piece, uint32_t index);
int del_piece(piece_t **head, piece_t *piece);
piece_t *search_piece(piece_t *head, uint32_t index);
piece_t *select_random_piece(const uint8_t *piece_map, piece_t **head, uint32_t *piece_count);
int select_block(const piece_t *piece, block_t *block, int no_of_pieces);
int del_piece_all(piece_t **piece_head);

#endif // ifndef _P2P_PIECE_H_ 

